<?php
//  This file is part of EkkinCMS.
//
//  EkkinCMS is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//
//  EkkinCMS is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with EkkinCMS.  If not, see <http://www.gnu.org/licenses/>.

$random_number1 = rand(1,1000000);
$random_number2 = rand(0,10);
$random_number3 = rand(0,10);

$anticaptcha_phrases = array(_("How much is")." $random_number2 + $random_number3?" => ($random_number2 + $random_number3),
                            _("How much digits has the number")." $random_number1?" => strlen("$random_number1"),
                            );
$n = 0;
$r = rand(0, count($anticaptcha_phrases)-1);
foreach($anticaptcha_phrases as $ac_phrase => $ac_answer){
    if ($n == $r) break;
}

$ac_key = "AC12jknK!#\$f$#%6favc";
$ac_answer = $anticaptcha_phrases[$ac_phrase];
$ac_answer_enc = string_encrypt($ac_answer, $ac_key);
$anticaptcha = _("Please answer the following security question:")."<br/><br/>
                <i>$ac_phrase</i> <br/>
                <input type=\"text\" name=\"security_answer\"/>
                <input type=\"hidden\" name=\"ac_answer\" value=\"$ac_answer_enc\"/>
";


function ac_check_answer($answer, $ac_answer_enc){
    global $ac_key;

    $ac_answer = string_decrypt($ac_answer_enc, $ac_key);

    //echo "$answer == $ac_answer ?";

    return $answer == $ac_answer;
}


